import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_tv_widgets/widgets/selectTag/select_tag_presets.dart';

import 'kq_select_tag.dart';

/// @author 高裕
/// KqSelectTag的预设工具
class SelectTagPresetsUtil {
  /// 加载预设实体
  static SelectTagPresetsEntity? presets(
      KqSelectTag widget, KqSelectTagState state, SelectTagPresets presets) {
    switch (presets) {
      case SelectTagPresets.normal:
        return _normalPresets(widget, state);
      case SelectTagPresets.textLeftScroll:
        return _textLeftScrollPresets(widget);
    }
  }

  /// 基本预设
  static SelectTagPresetsEntity? _normalPresets(
      KqSelectTag widget, KqSelectTagState state) {
    switch (widget.mode) {
      case KqSelectTagMode.share:
        return SelectTagPresetsEntity(
          bgPadding: EdgeInsets.symmetric(vertical: 8.r),
          itemPadding: EdgeInsets.symmetric(horizontal: 12.r, vertical: 4.r),
          itemMargin: EdgeInsets.symmetric(horizontal: 2.r),
          textSize: 20.sp,
        );
      case KqSelectTagMode.scroll:
        return SelectTagPresetsEntity(
          bgHeight: 48.r,
          bgPadding: EdgeInsets.symmetric(horizontal: 7.r, vertical: 8.r),
          itemPadding: EdgeInsets.symmetric(horizontal: 12.r, vertical: 4.r),
          itemMargin: EdgeInsets.symmetric(horizontal: 16.r),
          textSize: 20.sp,
        );
      case KqSelectTagMode.wrap:
        return SelectTagPresetsEntity(
          bgPadding: EdgeInsets.symmetric(vertical: 24.r),
          itemPadding: EdgeInsets.symmetric(horizontal: 28.r, vertical: 14.r),
          itemMargin: EdgeInsets.symmetric(horizontal: 16.r),
          textSize: 20.sp,
        );
      case KqSelectTagMode.smart:
        return state.changeToScroll()
            ? SelectTagPresetsEntity(
                bgHeight: 48.r,
                bgPadding: EdgeInsets.symmetric(horizontal: 7.r, vertical: 8.r),
                itemPadding:
                    EdgeInsets.symmetric(horizontal: 12.r, vertical: 4.r),
                itemMargin: EdgeInsets.symmetric(horizontal: 16.r),
                textSize: 20.sp,
              )
            : SelectTagPresetsEntity(
                bgPadding: EdgeInsets.symmetric(vertical: 8.r),
                itemPadding:
                    EdgeInsets.symmetric(horizontal: 12.r, vertical: 4.r),
                itemMargin: EdgeInsets.symmetric(horizontal: 2.r),
                textSize: 20.sp,
              );
    }
  }

  /// 纯文本居左滚动
  static SelectTagPresetsEntity? _textLeftScrollPresets(KqSelectTag widget) {
    // 非滚动模式此预设无效
    if (widget.mode != KqSelectTagMode.scroll) {
      return null;
    }
    return SelectTagPresetsEntity(
      bgHeight: 48.r,
      bgPadding: EdgeInsets.symmetric(horizontal: 6.r, vertical: 8.r),
      itemPadding: EdgeInsets.symmetric(horizontal: 8.r, vertical: 7.r),
      itemMargin: EdgeInsets.symmetric(horizontal: 2.r),
      textSize: 20.sp,
    );
  }
}

/// 预设实体
class SelectTagPresetsEntity {
  /// 背景高度
  final double? bgHeight;

  /// 背景颜色
  final Color? bgColor;

  /// 背景padding
  final EdgeInsetsGeometry? bgPadding;

  /// 文本大小
  final double? textSize;

  /// 文本选中颜色
  final Color? textSelectColor;

  /// 文本普通颜色
  final Color? textNormalColor;

  /// 文本最大行数
  final int? textMaxLine;

  /// 文本Overflow
  final TextOverflow? textOverflow;

  /// 文本样式
  final TextStyle? Function(int index)? textStyle;

  /// 自定义子项Decoration
  final Decoration? Function(int index)? itemDecoration;

  /// 子项大小限制
  final BoxConstraints? itemConstraints;

  /// 子项圆角
  final BorderRadiusGeometry? radius;

  /// 子项padding
  final EdgeInsetsGeometry? itemPadding;

  /// 子项margin
  final EdgeInsetsGeometry? itemMargin;

  /// 子项宽度
  final double? itemWidth;

  /// 子项高度
  final double? itemHeight;

  /// 子项选中颜色
  final Color? itemSelectColor;

  /// 子项普通颜色
  final Color? itemNormalColor;

  /// 子项边框
  final BoxBorder? Function(int index)? itemBoxBorder;

  /// warp的属性(主轴间距)
  final double? spacing;

  /// warp的属性(交叉轴间距)
  final double? runSpacing;

  /// warp的属性(主轴对齐方式)
  final WrapAlignment? wrapAlignment;

  /// warp的属性(叉轴对齐方式)
  final WrapCrossAlignment? wrapCrossAlignment;

  /// warp的属性(主轴垂直方向每一行的对齐方式)
  final WrapAlignment? wrapRunAlignment;

  /// 何时切换成滚动模式
  final WhenToScroll? whenToScroll;

  SelectTagPresetsEntity({
    this.bgColor,
    this.textSize,
    this.textStyle,
    this.textMaxLine,
    this.textOverflow,
    this.itemDecoration,
    this.itemConstraints,
    this.radius,
    this.itemPadding,
    this.itemMargin,
    this.bgPadding,
    this.bgHeight,
    this.itemWidth,
    this.itemHeight,
    this.textSelectColor,
    this.textNormalColor,
    this.itemSelectColor,
    this.itemNormalColor,
    this.itemBoxBorder,
    this.spacing,
    this.runSpacing,
    this.wrapAlignment,
    this.wrapCrossAlignment,
    this.wrapRunAlignment,
    this.whenToScroll,
  });
}
